#include "NewsCellWidget.h"

NewsCellWidget::NewsCellWidget(QWidget *parent): QWidget(parent), ui(new Ui::NewsCellWidgetClass())
{
	ui->setupUi(this);
	resize(500, 100);
	//resize(Constant::getInstance()->NewsCellWidgetSize);
}

NewsCellWidget::~NewsCellWidget()
{
	delete ui;
}

void NewsCellWidget::setUi(NewsCellData* newsCellData)
{
	this->newsCellData = newsCellData;
}

void NewsCellWidget::mouseReleaseEvent(QMouseEvent* ev)
{
	Q_UNUSED(ev)
	emit on_newsCell_click(this);
}

void NewsCellWidget::paintEvent(QPaintEvent* ev)
{
	int w = width(), h = height(); // 500, 100
	QPainter painter(this);

	QRect title(0, 0, w * 0.6, h * 0.5);
	painter.drawText(title, newsCellData->title);

	QRect userName(0, h * 0.5, w * 0.6, h * 0.5);
	painter.drawText(title, newsCellData->userName);

	QRect picture(w * 0.6, 0, w * 0.4, h);
	QPixmap pixmap(newsCellData->picture);
	painter.drawPixmap(picture, pixmap);
}
